<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../../resources/js-test.js"></script>
</head>
<body onload="runTest();">
<div id="gesture">

<p id="description"></p>
<div id="console"></div>

<script>
var expectedEvents = [
  {type: 'mousemove', x: 10, y: 12, detail: 0 },
  {type: 'mousedown', x: 10, y: 12, detail: 1 },
  {type: 'mouseup', x: 10, y: 12, detail: 1 },
  {type: 'click', x: 10, y: 12, detail: 1 },
  {type: 'mousemove', x: 11, y: 12, detail: 0 },
  {type: 'mousedown', x: 11, y: 12, detail: 2 },
  {type: 'mouseup', x: 11, y: 12, detail: 2 },
  {type: 'click', x: 11, y: 12, detail: 2 },
  {type: 'dblclick', x: 11, y: 12, detail: 2 },
  ];

var mouseEventsReceived = 0;

function gestureEventCallback(event)
{
    if (window.eventSender) {
        shouldBeEqualToString('event.type', expectedEvents[mouseEventsReceived].type);
        shouldEvaluateTo('event.clientX', expectedEvents[mouseEventsReceived].x);
        shouldEvaluateTo('event.clientY', expectedEvents[mouseEventsReceived].y);
        shouldEvaluateTo('event.detail', expectedEvents[mouseEventsReceived].detail);
        mouseEventsReceived++;
    } else {
        debug(event.type);
        debug(event.clientX);
        debug(event.clientY);
        debug(event.detail);
    }
}

// Because we may not have a gesture recognizer, we send a key press
// event to end the test without temporal flakiness.
function quitKeyToEndTest(event) {
    endTest();
}

function endTest()
{
    if (mouseEventsReceived < expectedEvents.length) {
        debug('Gesture manager not implemented on this platform.');
    }
    // Bail.
    isSuccessfullyParsed();
    testRunner.notifyDone();
}

function runTest() {
    var div = document.getElementById('gesture');
    div.addEventListener("mousedown", gestureEventCallback, false);
    div.addEventListener("click", gestureEventCallback, false);
    div.addEventListener("dblclick", gestureEventCallback, false);
    div.addEventListener("mouseup", gestureEventCallback, false);
    div.addEventListener("mousemove", gestureEventCallback, false);
    document.addEventListener("keydown", quitKeyToEndTest, false);

    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    if (window.eventSender) {
        description("This tests gesture callbacks for a double tap sequence of gestures.");
        eventSender.gestureTap(10, 12);
        eventSender.leapForward(10);
        eventSender.gestureTap(11, 12, 2);
        eventSender.leapForward(50);
        eventSender.keyDown(' ');
    } else {
        debug("This test requires DumpRenderTree.")
    }
}
</script>
</body>
</html>
